#include <iostream>
#include <string>

#include "BrowseMenu.h"
#include "BrowseItemMenu.h"

using std::cout;
using std::endl;
using std::string;

//Constructors

BrowseMenu::BrowseMenu(Stock* companyStock): SelectionMenu("Browse items of type:", "Back to main menu")
{
	for (int i = 0; i < 5; i++)
	{
		addSelection(companyStock -> getProductName(i));
	}
	addSelection("All types");
}

//Member Functions

void BrowseMenu::performAction(Stock* companyStock, Cart* theCart)
{
	string itemName;
	int userSelection;

	do {
		displayInfoBar();
		displayContent();
		cout << endl;

		userSelection = getSelectionFromUser();
		cout << endl;

		switch(userSelection)
		{
		case 0:
			break;
		default:
			if (userSelection == 6)
				itemName = "All types";
			else
				itemName = companyStock -> getProductName(userSelection - 1);

			BrowseItemMenu* itemSorter = new BrowseItemMenu(companyStock, userSelection - 1, itemName);
			itemSorter -> performAction(companyStock, theCart);
			delete itemSorter;

			break;
		}
	} while (userSelection != 0);

	cout << endl;
}